package cn.jsj.finance.bank;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.jsj.object.FrontInvoiceInfo;
import cn.jsj.pojo.TblInvoiceManage;
import cn.jsj.utils.SysLogger;

/**
 * 查询发票信息处理类
 * @author LI
 *
 */
 public class SearchInvoiceInfo extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
	 public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 调试信息
		 cn.jsj.utils.SysLogger.PrintInfo("查询发票信息");

		 //获取参数
		 String undertakeLawyer=request.getParameter("undertakeLawyer").trim();
		 String contractId=request.getParameter("contractId").trim();
		 undertakeLawyer=new String(undertakeLawyer.getBytes("ISO-8859-1"),"UTF-8");
		 contractId=new String(contractId.getBytes("ISO-8859-1"),"UTF-8");

		//获得参数：1.第几条开始。2.一页显示几条
		int startNumb=Integer.parseInt(request.getParameter("start"));
		int totalNumb=Integer.parseInt(request.getParameter("limit"));

		//新建后台到DB传递对象
		cn.jsj.bgtodb.SearchInvoiceProperty sip=new cn.jsj.bgtodb.SearchInvoiceProperty(undertakeLawyer,contractId,startNumb,totalNumb);

		//调试信息
		cn.jsj.utils.SysLogger.PrintInfo("start---->"+startNumb+"   total--------->"+totalNumb+"  "+undertakeLawyer+"  "+contractId);

		//获得发票信息条数
		cn.jsj.dao.TblInvoiceManageDAO timd=new cn.jsj.dao.TblInvoiceManageDAO();
		int invoiceNumber=timd.getSearchInvoiceNumb(sip);
		//发票信息列表
		java.util.List<TblInvoiceManage> invoiceList=new java.util.LinkedList<TblInvoiceManage>();
		invoiceList=timd.getSearchInvoiceInfo(sip);

		//前台发票信息对象队列
		java.util.List<FrontInvoiceInfo> frontInvoiceInfo=new java.util.LinkedList<FrontInvoiceInfo>();

		// 转换为前台发票信息对象
		cn.jsj.object.rebuild.InvoiceInfoRebuild iir=new cn.jsj.object.rebuild.InvoiceInfoRebuild();
		for(int i=0;i<invoiceList.size();i++){
			cn.jsj.object.FrontInvoiceInfo fii=iir.rebuildInvoiceInfo(invoiceList.get(i));
			frontInvoiceInfo.add(fii);
		}

		//转换成JSON型数据
		cn.jsj.utils.ProduceJsonData pjd=new cn.jsj.utils.ProduceJsonData();
		String jsonData=pjd.jsonFromList(frontInvoiceInfo, invoiceNumber);

		//调试信息
		SysLogger.PrintInfo(jsonData);
		//输出到客户端
		java.io.PrintWriter pw=response.getWriter();
		pw.println(jsonData);
		pw.flush();
		pw.close();

	}
}